package controls {
	
	import mx.controls.DataGrid;
	import mx.controls.dataGridClasses.DataGridColumn;
	import mx.core.Application;
	
	import org.siam.core.schemas.ISchemaManager;

	public class DataGridExample extends DataGrid {
		
		public function DataGridExample() {
			super();
		}
		
		public function configure(schemaId:String):void {
			var schemaManager:ISchemaManager = Application.application.siam.manage(schemaId);
			var columns:Array = new Array();
			for each (var propertyId:String in schemaManager.propertyIds) {
				var column:DataGridColumn = new DataGridColumn(propertyId);
				column.headerText = schemaManager.findMetadata("name", propertyId);
				column.itemRenderer = schemaManager.findRenderer(propertyId);
				columns.push(column);
			}
			this.columns = columns;
			labelFunction = function(item:Object, column:DataGridColumn):String {
  				return schemaManager.format(item, column.dataField);
  			}
  			invalidateDisplayList();
  			if (dataProvider)
				dataProvider.refresh();
		}
	}
}